import Vue from 'vue'
import Router from 'vue-router'
import storage from '@/utils/storage'

Vue.use(Router)

// console.log(routes)

const router = new Router()

/*
 * 全局守卫
 * @see https://router.vuejs.org/zh-cn/advanced/navigation-guards.html
 */
router.beforeEach((to, from, next) => {

  let user = storage.get('user')

  // 用户不存在，则跳转到登陆页
  if (to.path !== '/login' && user === null) {
      router.replace('/login')
  }

  next()
})

export default router